{% extends 'layout/basic.html' %}
{% load static %}

{% block title %}用户登录{% endblock %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/account.css' %}">
{% endblock %}

{% block content %}
    <div class="account">
        <div class="title">用户登录</div>
        <form method="POST" novalidate>
            {% csrf_token %}
            {% for field in form %}
                {% if field.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <div class="clearfix">
                            <div class="col-md-6" style="padding-left: 0">
                                {{ field }}
                                <span class="error_msg">{{ field.errors.0 }}</span>
                            </div>
                            <div class="col-md-6">
                                <img src="{% url 'img_code' %}" alt="" id="imgCode" title="点击刷新验证码">
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }}
                        <span class="error_msg">{{ field.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}
            <div class="row">
                <div class="col-xs-3">
                    <button id="login_submit" type="submit" class="btn btn-primary">登录</button>
                </div>
                <div class="col-xs-9" style="height: 34px">
                    <a href="{% url 'login_sms' %}" style="line-height: 34px" class="pull-right">短信验证码登录</a>
                </div>
            </div>
        </form>
    </div>
{% endblock %}
{% block js %}
    <script>
        {#点击验证码图片刷新#}
        $(function () {
            $('#imgCode').click(function () {
                let oldSrc = $(this).attr('src');
                $(this).attr('src', oldSrc + '?');
            })
        })
    </script>
{% endblock %}